package com.glsc.ngateway.platform.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import org.hibernate.annotations.Where;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Entity
@Data
@Table(name = "t_gw_flow_form_dev_task_detail")
public class FlowFormTaskDetail implements Serializable {

    @ApiModelProperty(value = "任务ID")
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "task_id", columnDefinition = "int comment '唯一编号'")
    private Integer taskId;

    @ApiModelProperty(value = "giteeTaskId")
    @Column(name = "gitee_task_id", columnDefinition = "varchar(60) comment 'giteeTaskId'")
    private String giteeTaskId;

    @ApiModelProperty(value = "流程ID")
    @Column(name = "process_id", columnDefinition = "varchar(60) comment '关联事件流程id'")
    private String processId;

    @ApiModelProperty(value = "是否删除标记，0未删除，1删除")
    @Column(name = "be_deleted", columnDefinition = "int comment '是否删除标记，0未删除，1删除'")
    private Integer beDeleted = 0;

    /**
     * 任务标题
     */
    @ApiModelProperty(value = "任务标题")
    @Column(name = "task_title", columnDefinition = "varchar(200) comment '任务标题'")
    String taskTitle;


    /**
     * 任务内容
     */
    @ApiModelProperty(value = "任务内容")
    @Column(name = "task_content", columnDefinition = "text comment '任务内容'")
    String taskContent;

    /**
     * 任务负责人账号
     */
    @ApiModelProperty(value = "任务负责人账号")
    @Column(name = "task_person_account", columnDefinition = "varchar(100) comment '任务负责人账号'")
    String taskPersonAccount;

    /**
     * 任务负责人姓名
     */
    @ApiModelProperty(value = "任务负责人姓名")
    @Column(name = "task_person_name", columnDefinition = "varchar(100) comment '任务负责人姓名'")
    String taskPersonName;

    @ApiModelProperty(value = "计划开始时间")
    @Column(name = "plan_date_begin", columnDefinition = "date comment '计划开始时间'")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    protected LocalDate planDateBegin;

    @ApiModelProperty(value = "计划完成时间")
    @Column(name = "plan_date", columnDefinition = "date comment '计划完成时间'")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    protected LocalDate planDate;

    @ApiModelProperty(value = "实际完成时间")
    @Column(name = "finish_date", columnDefinition = "date comment '实际完成时间'")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonSerialize(using = LocalDateSerializer.class)
    @JsonDeserialize(using = LocalDateDeserializer.class)
    protected LocalDate finishDate;

    @ApiModelProperty(value = "任务工时")
    @Column(name = "task_work_time", columnDefinition = "varchar(60) comment '任务工时'")
    private String taskWorkTime;

    /**
     * 优先级
     */
    @Column(name = "sort_no", columnDefinition = "varchar(10) comment '优先级'")
    private String sortNo;

    /**
     * 任务流程id
     */
    //事件流程会触发任务流程，这个字段保存这个关系
    @ApiModelProperty(value = "事件任务措施触发任务流程ID")
    @Column(name = "task_process_id", columnDefinition = "varchar(60) comment '任务措施触发的任务流程id'")
    private String taskProcessId;

    /**
     * 任务状态
     */
    @ApiModelProperty(value = "任务状态 字典")
    @Column(name = "task_state", columnDefinition = "varchar(10) comment '录入后为待开发状态'")
    private String taskState;

    @ApiModelProperty(value = "gitee原始状态 字典")
    @Column(name = "gitee_orignal_state", columnDefinition = "varchar(10) comment 'gitee原始状态'")
    private String giteeOrignalState;

    @Column(name = "gitee_ident", columnDefinition = "varchar(10) comment 'gitee标识'")
    private String giteeIdent;

    @Column(name = "gitee_url", columnDefinition = "varchar(500) comment 'gitee超链接'")
    private String giteeUrl;

    @ApiModelProperty(value = "前后端-字典frontOrBack")
    @Column(name = "front_or_back", columnDefinition = "varchar(10) comment '标记是否为前后端-字典frontOrBack'")
    private String frontOrBack;

    @ApiModelProperty(value = "giteeDataBaseId")
    @Column(name = "gitee_data_base_id", columnDefinition = "varchar(10) comment 'giteeDataBaseId'")
    private String giteeDataBaseId;

    @ApiModelProperty(value = "giteeDataBaseName")
    @Column(name = "gitee_data_base_name", columnDefinition = "varchar(10) comment 'giteeDataBaseName'")
    private String giteeDataBaseName;

    @Column(name = "gitee_data_base_branch_status", columnDefinition = "varchar(10) comment '创建分支状态'")
    private String giteeDataBaseBranchStatus;

    @Column(name = "insert_time", columnDefinition = "datetime comment '创建时间'")
    @CreationTimestamp
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    protected LocalDateTime insertTime;

    @Column(name = "update_time", columnDefinition = "datetime comment '更新时间'")
    @UpdateTimestamp
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    protected LocalDateTime updateTime;

    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    @JoinColumn(name = "relate_id", referencedColumnName = "task_id", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    @Where(clause = " relate_type=2 ")//仅未删除状态的
    @org.hibernate.annotations.OrderBy(clause = " insert_time desc ")
    @ApiModelProperty(value = "整改明细")
    List<DevTaskChangeLog> detailLog;

}
